/*
 * Copyright 2007-2009 Perttu "celeron55" Ahola <celeron55@gmail.com>
 *
 * This file is part of jukumagic.
 *
 * jukumagic is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * jukumagic is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with jukumagic.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef OBJECTCONTAINER_H_
#define OBJECTCONTAINER_H_

#include <list>
#include <set>
#include "common.h"
#include "jukuobject.h"

class ObjectContainer : public JukuObject
{
private:
	std::list<JukuObject*> m_objects;
	std::set<JukuObject*> m_selected_objects;
	bool m_ignore_changes;

protected:
	void ChildChanged(ObjectChangeType type, JukuObject *obj);
	void SelfChanged(ObjectChangeType type);
public:
	ObjectContainer();
	virtual ~ObjectContainer();

    JukuObjectType GetType()const{ return TYPE_OBJECTCONTAINER; }
	const wxChar * GetShortString(void)const{return NULL;}
	const wxChar * GetTypeString(void)const{return _("ObjectContainer");}

	virtual void WriteBaseXML(TiXmlElement *element);
	virtual void ReadBaseXML(TiXmlElement *element);

	// When this receives obj=self, it means it affects many objects in the container
	//virtual void ContainerChildChanged(JukuObject *obj, ObjectChangeType type, int level){}
	
	void Clear();
	void Clear(std::set<JukuObject*> &objects);
	const std::list<JukuObject*> & GetObjects();
	virtual bool Add(JukuObject *object, JukuObject *prev_object);
	
	// Set selection of all the objects and the container
	virtual void SetSelected(bool selected);
	
	virtual const std::set<JukuObject*> & GetSelectedObjects();
	
	/*
		This is a lot faster than selecting each one by one.
		Does no error checking.
	*/
	virtual void SelectChildren(const std::set<JukuObject*> & objects);
	virtual void MoveChildren(const std::set<JukuObject*> & objects, int dx, int dy);

	void DeleteSelectedObjects();
	void operator = (ObjectContainer &c);
};

#endif
